#include <stdio.h>
#include <stdlib.h>


typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;
    PtrToNode   Next;
};
typedef PtrToNode List;


List Read();
void Print( List L );

List UnionList( List L1, List L2 );

int main()
{
    List L1, L2, L;
    L1 = Read();
    L2 = Read();
    L = UnionList(L1, L2);
    Print(L);
    return 0;
}

List Read() {
    List r,L=(struct Node*)malloc(sizeof(struct Node));
    L->Next=NULL;
    r=L;
    int n = 0;
    while(1) {///尾插法
        scanf("%d",&n);
        if(n == -1){
            break;
        }
        PtrToNode p=(struct Node*)malloc(sizeof(struct Node));
        p->Data=n;
        p->Next=NULL;
        r->Next=p;
        r=p;
    }
    return L;
}



void Print(List L) {
    if(L->Next != NULL) {
        List r=L;
        while(r->Next) {
            r=r->Next;
            printf("%d",r->Data);
            if(r -> Next != NULL){
                printf(" ");
            }
        }
    } else {
        printf("NULL\n");
    }
}


List UnionList( List L1, List L2 ){
    List head =(List)malloc(sizeof(struct Node));
    head->Next=NULL;
    if(L1->Next == NULL || L2->Next == NULL){
        return head;
    }
    List p=L1->Next;
    List q=L2->Next;
    List rear=head;
    while (p != NULL && q != NULL){
        if(p->Data < q->Data){
            p = p->Next;
        } else if(q ->Data < p ->Data){
            q = q->Next;
        } else{
            List tmp=(List)malloc(sizeof(struct Node));
            tmp->Data=p->Data;
            tmp->Next=NULL;
            rear->Next=tmp;
            rear=rear->Next;
            p = p -> Next;
            q = q -> Next;
        }
    }
    return head;
}

